<template>
	<view class="id_card">
		<image src="../../static/nologin.png"></image>
		<view>身份证智能识别</view>
	</view>
	
	<up-form :labelWidth="70" :model="addForm"> 
		<up-form-item label="真实名称">
			<up-input v-model="addForm.name"></up-input>
		</up-form-item>
		<up-form-item label="性别">
			<picker  range-key="name" @change="getSex"  :range="sexList" :value="sexIndex">
				 <view>{{sexList[sexIndex].name}}</view>
			</picker>
		</up-form-item>
		<up-form-item label="出生日期">
		   <picker start="1980-09-01" @change="getDate"  end="2025-09-01" mode="date" value="{{date}}">
			    <view>{{date}}</view>
		   </picker>
		</up-form-item>
		<up-form-item label="关系">
			<picker range-key="name" @change="getRela" :range="relaList" :value="relaIndex">
				 <view>{{relaList[relaIndex].name}}</view>
			</picker>
		</up-form-item>
		<up-form-item label="身份证">
			<up-input v-model="addForm.id_card"></up-input>
		</up-form-item>
		
		<up-form-item label="手机号">
			<up-input v-model="addForm.phone"></up-input>
		</up-form-item>
		  <up-form-item >
			  <view style="display: flex; justify-content: space-around;">
				  <view>
					  <up-button style="width: 100px;" text="取消" type="primary" ></up-button>
				  </view>
				 <view>
					<up-button @click="toAdd" style="width: 100px;"  text="确定添加" type="primary"></up-button>
				 </view>
			</view>
		  </up-form-item>
	</up-form>
</template>

<script setup>
	import {addPatient} from '@/api/user.js'
	import {ref,reactive} from 'vue'
	
	
	let addForm=reactive({
		name:"",
		sex:"",
		born:"",
		relation:"",
		phone:"",
		id_card:""
	})
	

	let sexList=ref([{name:"男",id:1},{name:"女",id:2}])
	let sexIndex=ref(0)//改变当前选择的数据下标
	
	let date=ref('请选择时间');
	
	let relaList=ref([{name:"父母"},{name:"自己"},{name:"其他"}])
	let relaIndex=ref(0);
	
	let getSex=(e)=>{ //性别
		addForm.sex=sexList.value[e.detail.value].name;
		sexIndex.value=e.detail.value;//改变当前选择的数据下标
	}
	let getDate=(e)=>{ //日期
		addForm.born=e.detail.value;
		date.value=e.detail.value;
	}
	let getRela=(e)=>{ //关系 
		addForm.relation=relaList.value[e.detail.value].name;
		relaIndex.value=e.detail.value;
	}
	
	let  toAdd=async ()=>{
		console.log(addForm,"收集到的数据----")
		let res=await addPatient(addForm)
		console.log(res,"------发送-----")
		uni.showToast({
			title:"添加就诊人成功"
		})
		uni.navigateTo({ //就诊人列表
			url:"/pages/addperson/list"
		})
	}
</script>

<style lang="scss">
	.id_card{
		display: flex;
		height: 70px;
		align-items: center;
		image{
			width: 140rpx;
			height: 140rpx;
		}
		border-bottom: 1px solid black;
	}
</style>